package cn.stylefeng.guns.goodsdetail.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.stylefeng.guns.core.annotion.BusinessLog;
import cn.stylefeng.guns.core.enums.LogAnnotionOpTypeEnum;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.core.pojo.response.SuccessResponseData;
import cn.stylefeng.guns.goodsdetail.dto.GoodsDetailDTO;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import cn.stylefeng.guns.goodsdetail.service.GoodsDetailService;
import cn.stylefeng.guns.goodsdetail.model.param.GoodsDetailParam;

import javax.annotation.Resource;

/**
 * goods_detail 控制器
 *
 * @author: aria
 * @date: 2021/02/20 20:24
 */
@Api("goods_detail控制器")
@RestController
public class GoodsDetailController {

    @Resource
    private GoodsDetailService goodsDetailService;

    /**
     * 分页查询goods_detail
     *
     * @author aria
     * @date 2021/02/20 20:24
     */
    @GetMapping("/goodsDetail/page")
    @BusinessLog(title = "goods_detail_分页查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData page(GoodsDetailParam goodsDetailParam) {
        GoodsDetailDTO goodsDetailDTO = new GoodsDetailDTO();
        BeanUtil.copyProperties(goodsDetailParam,goodsDetailDTO);
        return new SuccessResponseData(goodsDetailService.page(goodsDetailDTO));
    }

    /**
     * 获取全部goods_detail
     *
     * @author aria
     * @date 2021/02/20 20:24
     */
    @GetMapping("/goodsDetail/list")
    @BusinessLog(title = "goods_detail_查询所有", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(GoodsDetailParam goodsDetailParam) {
        GoodsDetailDTO goodsDetailDTO = new GoodsDetailDTO();
        BeanUtil.copyProperties(goodsDetailParam,goodsDetailDTO);
        return new SuccessResponseData(goodsDetailService.list(goodsDetailDTO));
    }

    /**
     * 查看详情goods_detail
     *
     * @author aria
     * @date 2021/02/20 20:24
     */
    @GetMapping("/goodsDetail/detail")
    @BusinessLog(title = "goods_detail_查看详情", opType = LogAnnotionOpTypeEnum.DETAIL)
    public ResponseData detail(@Validated(GoodsDetailParam.detail.class) GoodsDetailParam goodsDetailParam) {
        GoodsDetailDTO goodsDetailDTO = new GoodsDetailDTO();
        BeanUtil.copyProperties(goodsDetailParam,goodsDetailDTO);
        return new SuccessResponseData(goodsDetailService.detail(goodsDetailDTO));
    }

    /**
     * 添加goods_detail
     *
     * @author aria
     * @date 2021/02/20 20:24
     */
    @PostMapping("/goodsDetail/add")
    @BusinessLog(title = "goods_detail_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated(GoodsDetailParam.add.class) GoodsDetailParam goodsDetailParam) {
        GoodsDetailDTO goodsDetailDTO = new GoodsDetailDTO();
        BeanUtil.copyProperties(goodsDetailParam,goodsDetailDTO);
        goodsDetailService.add(goodsDetailDTO);
        return new SuccessResponseData();
    }

    /**
     * 删除goods_detail
     *
     * @author aria
     * @date 2021/02/20 20:24
     */
    @PostMapping("/goodsDetail/delete")
    @BusinessLog(title = "goods_detail_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(GoodsDetailParam.delete.class) GoodsDetailParam goodsDetailParam) {
        GoodsDetailDTO goodsDetailDTO = new GoodsDetailDTO();
        BeanUtil.copyProperties(goodsDetailParam,goodsDetailDTO);
        goodsDetailService.delete(goodsDetailDTO);
        return new SuccessResponseData();
    }

    /**
     * 编辑goods_detail
     *
     * @author aria
     * @date 2021/02/20 20:24
     */
    @PostMapping("/goodsDetail/edit")
    @BusinessLog(title = "goods_detail_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(GoodsDetailParam.edit.class) GoodsDetailParam goodsDetailParam) {
        GoodsDetailDTO goodsDetailDTO = new GoodsDetailDTO();
        BeanUtil.copyProperties(goodsDetailParam,goodsDetailDTO);
        goodsDetailService.edit(goodsDetailDTO);
        return new SuccessResponseData();
    }


}
